package com.lxh.cp.handler;

import com.lxh.cp.builder.ImageBuilder;
import com.lxh.cp.builder.NewsBuilder;
import com.lxh.cp.builder.TextBuilder;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpXmlMessage;
import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * created by lanxinghua@2dfire.com on 2020/2/23
 */
@Component
public class MsgHandler extends AbstractHandler {

  @Override
  public WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage, Map<String, Object> context, WxCpService cpService,
                                  WxSessionManager sessionManager) {

    //TODO 可以选择将消息保存到本地
    if (!wxMessage.getMsgType().equals(WxConsts.XmlMsgType.EVENT)) {

    }
    
    // 消息处理
    String content = wxMessage.getContent();
    WxCpXmlOutMessage xmlOutMessage = new TextBuilder().build(content, wxMessage, cpService);
    switch (content) {
      case "图片": {
        content = "1JwpbLSisNzaUb8dGiR6stmseQcRORha2Md9DeV829-1W_G56F6gjsO5ClJ7isccW";
        xmlOutMessage = new ImageBuilder().build(content, wxMessage, cpService);
        break;
      }
      case "语音": {
        break;
      }
      case "图文": {
        xmlOutMessage = new NewsBuilder().build(content, wxMessage, cpService);
        break;
      }
      default: {
        xmlOutMessage = new TextBuilder().build(content, wxMessage, cpService);
        break;
      }
    }
    return xmlOutMessage;
  }
}
